package com.wcj.sort;

public class 希尔排序 {

    public static void main(String[] args) {
        int[] arr = new int[]{23,12,36,451,2,89,78,54};
        shellSort(arr);
        for (int i : arr) {
            System.out.println(i);
        }
    }

    public static void shellSort(int[] arr){
        int j;
        for (int gap = arr.length/2; gap > 0; gap/=2){
            for (int i = gap; i < arr.length; i++){
                int tmp = arr[i];
                for (j=i; j >= gap && tmp < arr[j - gap];j -= gap){
                    arr[j] = arr[j - gap];
                }
                arr[j] = tmp;
            }
        }
    }


}
